home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Memphis Amiga Group / MAG Disk (1990-01)(Memphis Amiga Group).zip / MAG Disk (1990-01)(Memphis Amiga Group).adf / showfont.c < prev    next >
C/C++ Source or Header  |  1989-12-29  |  38KB  |  1,495 lines

  1. /*********************************************************/
  2. /*     ShowFont 4.0 © 1989 by Arthur Johnson Jr.     */
  3. /* ===================================================== */
  4. /* Usage:  ShowFont [font_name] [font_size] [font_style] */
  5. /* ===================================================== */
  6. /*           Last modifications - 07/12/89         */
  7. /*********************************************************/
  8.  
  9. #include "intuition/intuition.h"
  10. #include "exec/memory.h"
  11. #include "libraries/diskfont.h"
  12. #include "libraries/dos.h"
  13. #include "libraries/dosextens.h"
  14.  
  15. #define XAREA        20        /* no characters beyond (screenwidth - XAREA) */
  16. #define FONTBUFFER  5000    /* hopefully enough for most people */
  17. #define FONTNAMELEN 30        /* maximum font name length */
  18. #define MAXSTYLES   15        /* that should be enough */
  19. #define NUMSTYLES   4        /* Underlined, Bold, Italics, Extended */
  20.  
  21. #define MAXDISPLAY  8        /* max names, sizes, and styles to display */
  22. #define NAMELEN     20        /* maximum chars of name displayed */
  23. #define NAMEXPOS    8
  24. #define SIZEXPOS    200
  25. #define STYLXPOS    256
  26. #define TOPYPOS     8
  27.  
  28. #define BASELINE    6    /* for Topaz-8 font */
  29. #define XINCR        8
  30. #define YINCR        8
  31.  
  32. /* these are short little macro expanders to save me some typing effort */
  33. #define SIZES        fonts[namesel].sizes
  34. #define SIZESEL     fonts[namesel].sizesel
  35. #define STYLES        fonts[namesel].size[SIZESEL].styles
  36. #define STYLE        fonts[namesel].size[SIZESEL].style
  37. #define STYLESEL    fonts[namesel].size[SIZESEL].stylesel
  38.  
  39. extern struct DosLibrary *DOSBase;
  40.  
  41. extern struct NewScreen NewScreenStructure;
  42. extern struct NewWindow NewWindowStructure1;
  43. extern struct Menu Menu1;
  44. extern struct Requester FontRequesterStructure2;
  45. extern struct Requester AboutRequesterStructure3;
  46. extern struct Requester FehRequesterStructure4;
  47. extern struct Requester ScreenRequesterStructure5;
  48. extern struct Requester DirRequesterStructure6;
  49. extern struct PropInfo PropSInfo;
  50. extern struct PropInfo FontFontFontSInfo;
  51. extern struct PropInfo FontFontSizeSInfo;
  52. extern struct PropInfo FontFontStyleSInfo;
  53. extern struct Gadget Prop;
  54. extern struct Gadget FontFont;
  55. extern struct Gadget FontSize;
  56. extern struct Gadget FontStyle;
  57. extern struct Gadget ScreenGadget9;
  58. extern struct Gadget ScreenGadget10;
  59. extern struct Gadget ScreenGadget11;
  60. extern struct Gadget ScreenGadget12;
  61. extern struct Gadget ScreenGadget13;
  62. extern struct Gadget ScreenGadget14;
  63. extern struct Gadget ScreenGadget15;
  64. extern struct Gadget ScreenGadget16;
  65. extern struct Gadget ScreenGadget17;
  66. extern UBYTE DirDirNewDirSIBuff[];
  67. extern struct Gadget DirNewDir;
  68. extern UBYTE errormessage[];
  69. extern struct IntuiText FehIText15;
  70.  
  71. struct Screen *screen;
  72. struct Window *window;
  73. struct RastPort *rp;
  74. struct Gadget *whichgad;
  75. struct IntuiMessage *message;
  76.  
  77. struct IntuitionBase *IntuitionBase;
  78. struct GfxBase *GfxBase;
  79. struct DiskfontBase *DiskfontBase;
  80.  
  81. struct sizenode {
  82.     UWORD ysize;
  83.     int   styles;
  84.     UBYTE style[MAXSTYLES];
  85.     UBYTE flags;
  86.     int   stylesel;
  87. };
  88.  
  89. struct tempsizenode {
  90.     UWORD ysize;
  91.     int   styles;
  92.     UBYTE style[MAXSTYLES];
  93.     UBYTE flags;
  94.     struct tempsizenode *prev;
  95.     struct tempsizenode *next;
  96. };
  97.  
  98. struct fontinfo {
  99.     char    name[FONTNAMELEN + 1];
  100.     int     sizes;
  101.     struct  sizenode *size;
  102.     int     sizesel;
  103. };
  104. struct fontinfo *fonts;
  105.  
  106. struct tempfontinfo {
  107.     char    name[FONTNAMELEN + 1];
  108.     int     sizes;
  109.     struct  tempsizenode *size;
  110.     struct  tempfontinfo *prev;
  111.     struct  tempfontinfo *next;
  112. };
  113. struct tempfontinfo *tempfonts;
  114.  
  115. char fontname[FONTNAMELEN + 6]; /* include space for '.font\0' */
  116. struct TextAttr myfont = { /* necessary structure for fonts */
  117.     &fontname[0],   /* default is Topaz-8 fault */
  118.     8,
  119.     FS_NORMAL,
  120.     FPF_ROMFONT };
  121. struct TextFont *font;
  122.  
  123. struct {
  124.     UBYTE *string;
  125.     int length;
  126. } fontline[256];    /* maximum of 256 lines (one char/line) */
  127.  
  128. /* I just don't want to pass the following values around */
  129.  
  130. int numfonts;
  131.  
  132. int screenwidth = 640,
  133.     screenheight = 200,
  134.     screendepth = 2;
  135.  
  136. int nameline, sizeline, styleline,
  137.     namesel,
  138.     rfontlastline, rsizelastline, rstylelastline;
  139.  
  140. USHORT fontpropsize, fontproppos, sizepropsize, sizeproppos,
  141.     stylepropsize, styleproppos;
  142.  
  143. UBYTE qualifiers[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  144.                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  145.                0, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 0, 0, 0,
  146.                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2,
  147.                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  148.                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2,
  149.                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  150.                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 5,
  151.                5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  152.                5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  153.                3, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 3, 3, 3, 3,
  154.                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 4,
  155.                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  156.                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4,
  157.                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  158.                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 3 };
  159.  
  160. char whichkey[] = { '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  161.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  162.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  163.             'X', 'Y', 'Z', '?', '?', '?', '?', '?',
  164.             's', '1', '\'', '3', '4', '5', '7', '\'',
  165.             '9', '0', '8', '=', ',', '-', '.', '/',
  166.             '0', '1', '2', '3', '4', '5', '6', '7',
  167.             '8', '9', ';', ';', ',', '=', '.', '/',
  168.             '2', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  169.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  170.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  171.             'X', 'Y', 'Z', '[', '\\', ']', '6', '-',
  172.             '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  173.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  174.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  175.             'X', 'Y', 'Z', '[', '\\', ']', '`', '?',
  176.             '?', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  177.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  178.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  179.             'X', 'Y', 'Z', '?', '?', '?', '?', '?',
  180.             's', '1', '\'', '3', '4', '5', '7', '\'',
  181.             '9', '0', '8', '=', ',', '-', '.', '/',
  182.             '0', '1', '2', '3', '4', '5', '6', '7',
  183.             '8', '9', ';', ';', '-', '=', '.', '/',
  184.             '2', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  185.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  186.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  187.             'X', 'Y', 'Z', '[', '\\', ']', '6', '-',
  188.             '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  189.             'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  190.             'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  191.             'X', 'Y', 'Z', '[', '\\', ']', '\'', 'm' };
  192.  
  193. void error(char *), clearfonts(), clearfontlines(), cleanup(char *),
  194.      cleartempsize(struct tempfontinfo *), cleartempfonts(),
  195.      addsizenode(struct tempfontinfo *, UWORD, UBYTE, UBYTE), readfonts(),
  196.      setupscreen(), refresh1(struct RastPort *),
  197.      refresh2(struct RastPort *), refresh3(struct RastPort *),
  198.      updateprop(struct Gadget *, struct Requester *, USHORT, USHORT),
  199.      duhprop(struct RastPort *, int), *findfonts(), makewindowtitle(char *),
  200.      main(int, char *[]);
  201.  
  202. int stylenum(UBYTE), definescreen(), findfont(),
  203.     propline(USHORT, int), selectfont(), changefontsdir();
  204.  
  205. USHORT proppos(int, int), propsize(int, int);
  206.  
  207. void error(char *s)
  208. {
  209.  
  210.     ULONG class;
  211.  
  212.     strcpy(errormessage, s);
  213.     FehIText15.LeftEdge = (100 - ((strlen(s) * XINCR) / 2));
  214.     Request(&FehRequesterStructure4, window);
  215.  
  216.     do {
  217.     while ((message = (struct IntuiMessage *)GetMsg(window->UserPort)) == 0) { }
  218.     class = message->Class;
  219.     ReplyMsg(message);
  220.     } while (class != GADGETUP);
  221.  
  222. }
  223.  
  224. void clearfonts()
  225. {
  226.  
  227.     register i;
  228.  
  229.     for (i = 0; i < numfonts; i++)
  230.     FreeMem(fonts[i].size, fonts[i].sizes * sizeof(struct sizenode));
  231.     FreeMem(fonts, numfonts * sizeof(struct fontinfo));
  232.  
  233.     numfonts = 0;   /* there are no fonts */
  234.  
  235. }
  236.  
  237. void clearfontlines()
  238. {
  239.  
  240.     register i = 0;
  241.  
  242.     while (fontline[i].length != 0) {
  243.     FreeMem(fontline[i].string, fontline[i].length);
  244.     fontline[i].length = 0;
  245.     ++i;
  246.     }
  247.  
  248. }
  249.  
  250. void cleanup(char *text)
  251. {
  252.  
  253.     clearfontlines();
  254.     clearfonts();
  255.     if (font)
  256.     CloseFont(font);
  257.     if (window) {
  258.     ClearMenuStrip(window);
  259.     CloseWindow(window);
  260.     }
  261.     if (screen)
  262.     CloseScreen(screen);
  263.     if (DiskfontBase)
  264.     CloseLibrary(DiskfontBase);
  265.     if (IntuitionBase)
  266.     CloseLibrary(IntuitionBase);
  267.     if (GfxBase)
  268.     CloseLibrary(GfxBase);
  269.  
  270.     if (text)
  271.     puts(text);
  272.  
  273.     exit(0);
  274.  
  275. }
  276.  
  277. void cleartempsize(struct tempfontinfo *font)
  278. {
  279.  
  280.     struct tempsizenode *erase;
  281.  
  282.     while (font->size != NULL) {
  283.     erase = font->size;
  284.     font->size = font->size->next;
  285.     FreeMem(erase, sizeof(struct tempsizenode));
  286.     }
  287.  
  288. }
  289.  
  290. void cleartempfonts()
  291. {
  292.  
  293.     struct tempfontinfo *erase;
  294.  
  295.     while (tempfonts != NULL) {
  296.     erase = tempfonts;
  297.     tempfonts = tempfonts->next;
  298.     cleartempsize(erase);
  299.     FreeMem(erase, sizeof(struct tempfontinfo));
  300.     }
  301.  
  302. }
  303.  
  304. int stylenum(UBYTE style)
  305. {
  306.  
  307.     int flags = 0;
  308.  
  309.     if (style == FS_NORMAL) {
  310.     return(0);
  311.     }
  312.     if (style & FSF_UNDERLINED) {
  313.     flags |= 1;
  314.     }
  315.     if (style & FSF_BOLD) {
  316.     flags |= 2;
  317.     }
  318.     if (style & FSF_ITALIC) {
  319.     flags |= 4;
  320.     }
  321.     if (style & FSF_EXTENDED) {
  322.     flags |= 8;
  323.     }
  324.  
  325.     return(flags);
  326.  
  327. }
  328.  
  329. void addsizenode(struct tempfontinfo *font, UWORD ysize, UBYTE style, UBYTE flags)
  330. {
  331.  
  332.     struct tempsizenode *search, *prev, *newnode;
  333.  
  334.     int foundit = FALSE;
  335.  
  336.     prev = NULL;
  337.     search = font->size;
  338.     while (search != NULL) {
  339.     if ((search->ysize == ysize) && (search->flags == flags)) {
  340.         search->style[search->styles] = stylenum(style);
  341.         ++(search->styles);
  342.         foundit = TRUE;
  343.         break;
  344.     }
  345.     else {
  346.         if (search->ysize >= ysize) /* should go before this size */
  347.         break;
  348.         else {
  349.         prev = search;
  350.         search = search->next;
  351.         }
  352.     }
  353.     }
  354.     if (!foundit) {
  355.     newnode = (struct tempsizenode *)AllocMem(sizeof(struct tempsizenode), MEMF_CLEAR);
  356.     if (newnode == NULL)
  357.         cleanup("ShowFont: couldn't allocate 'tempsizenode' memory!");
  358.     newnode->ysize = ysize;
  359.     newnode->styles = 0;
  360.     newnode->flags = flags;
  361.     newnode->style[newnode->styles] = stylenum(style);
  362.     ++(newnode->styles);
  363.     ++(font->sizes);
  364.     if (font->size == NULL) {   /* list is empty */
  365.         newnode->prev = NULL;
  366.         newnode->next = NULL;
  367.         font->size = newnode;
  368.     }
  369.     else {
  370.         if (search == NULL) {   /* add at end o' list */
  371.         prev->next = newnode;
  372.         newnode->prev = prev;
  373.         newnode->next = NULL;
  374.         }
  375.         else {
  376.         if (search->prev == NULL) { /* add at beginning o' list */
  377.             newnode->prev = NULL;
  378.             newnode->next = search;
  379.             search->prev = newnode;
  380.             font->size = newnode;
  381.         }
  382.         else {    /* add in the middle o' the list */
  383.             search->prev->next = newnode;
  384.             newnode->prev = search->prev;
  385.             newnode->next = search;
  386.             search->prev = newnode;
  387.         }
  388.         }
  389.     }
  390.     }
  391.  
  392. }
  393.  
  394. void readfonts()
  395. {
  396.  
  397.     struct AvailFontsHeader *afh;
  398.     struct AvailFonts *af;
  399.  
  400.     struct tempfontinfo *search, *prev, *newnode;
  401.     struct tempsizenode *sizenode;
  402.  
  403.     char searchname[FONTNAMELEN + 6];
  404.  
  405.     int foundit;
  406.  
  407.     int mem = FONTBUFFER,
  408.     moremem;
  409.  
  410.     register i, j, k;
  411.  
  412.     clearfonts();
  413.  
  414.     do {
  415.     afh = (struct AvailFontsHeader *)AllocMem(mem, MEMF_CLEAR);
  416.     if (afh == NULL)
  417.         cleanup("ShowFont: couldn't allocate 'AvailFontsHeader' memory!");
  418.     moremem = AvailFonts(afh, mem, 0xFF);
  419.     if (moremem != 0) {
  420.         FreeMem(afh, mem);
  421.         mem += moremem;
  422.         printf("ShowFont: allocating %d bytes of memory for the FONTS: info.\n", mem);
  423.     }
  424.     } while (moremem != 0);
  425.  
  426.     if (afh->afh_NumEntries == 0) {
  427.     FreeMem(afh, mem);
  428.     cleanup("ShowFont: couldn't find any fonts! (Is FONTS: set correctly?)");
  429.     }
  430.  
  431.     tempfonts = NULL;
  432.  
  433.     af = (struct AvailFonts *)&afh[1];
  434.     for (i = 0; i < afh->afh_NumEntries; i++) {
  435.     if (!((af->af_Attr.ta_Flags & FPF_REMOVED) ||
  436.         (af->af_Attr.ta_Flags & FPF_REVPATH) ||
  437.         ((af->af_Type & AFF_MEMORY) &&
  438.          (af->af_Attr.ta_Flags & FPF_DISKFONT)))) {
  439.  
  440.         prev = NULL;
  441.         search = tempfonts;
  442.         foundit = FALSE;
  443.         while (search != NULL) {
  444.         strcpy(searchname, search->name);
  445.         strcat(searchname, ".font");
  446.         if (stricmp(af->af_Attr.ta_Name, searchname) == 0) {
  447.             addsizenode(search, af->af_Attr.ta_YSize, af->af_Attr.ta_Style, af->af_Attr.ta_Flags);
  448.             foundit = TRUE;
  449.             break;
  450.         }
  451.         else {
  452.             if (stricmp(af->af_Attr.ta_Name, searchname) < 0)
  453.             break;    /* should go before here */
  454.             else {
  455.             prev = search;
  456.             search = search->next;
  457.             }
  458.         }
  459.         }
  460.         if (!foundit) {
  461.         newnode = (struct tempfontinfo *)AllocMem(sizeof(struct tempfontinfo), MEMF_CLEAR);
  462.         if (newnode == NULL)
  463.             cleanup("ShowFont: couldn't allocate 'tempfontinfo' memory!");
  464.         stccpy(newnode->name, af->af_Attr.ta_Name, (strlen(af->af_Attr.ta_Name) - 4));
  465.         newnode->sizes = 0;
  466.         newnode->size = NULL;
  467.         addsizenode(newnode, af->af_Attr.ta_YSize, af->af_Attr.ta_Style, af->af_Attr.ta_Flags);
  468.         ++numfonts;
  469.         if (tempfonts == NULL) { /* list is empty */
  470.             newnode->prev = NULL;
  471.             newnode->next = NULL;
  472.             tempfonts = newnode;
  473.         }
  474.         else {
  475.             if (search == NULL) {   /* should add at end */
  476.             prev->next = newnode;
  477.             newnode->prev = prev;
  478.             newnode->next = NULL;
  479.             }
  480.             else {
  481.             if (search->prev == NULL) { /* add at beginning */
  482.                 newnode->prev = NULL;
  483.                 newnode->next = search;
  484.                 search->prev = newnode;
  485.                 tempfonts = newnode;
  486.             }
  487.             else { /* add in the middle o' the list */
  488.                 search->prev->next = newnode;
  489.                 newnode->prev = search->prev;
  490.                 newnode->next = search;
  491.                 search->prev = newnode;
  492.             }
  493.             }
  494.         }
  495.         }
  496.     }
  497.     af++;
  498.     }
  499.  
  500.     FreeMem(afh, mem);
  501.  
  502.     if ((fonts = (struct fontinfo *)AllocMem(numfonts * sizeof(struct fontinfo), MEMF_CLEAR)) == NULL)
  503.     cleanup("ShowFont: couldn't allocate 'fontinfo' memory!");
  504.  
  505.     search = tempfonts;
  506.  
  507.     for (i = 0; i < numfonts; i++) {
  508.     strcpy(fonts[i].name, search->name);
  509.     fonts[i].sizes = search->sizes;
  510.     if ((fonts[i].size = (struct sizenode *)AllocMem(fonts[i].sizes * sizeof(struct sizenode), MEMF_CLEAR)) == NULL)
  511.         cleanup("ShowFont: couldn't allocate 'sizenode' memory!");
  512.     sizenode = search->size;
  513.     for (j = 0; j < fonts[i].sizes; j++) {
  514.         fonts[i].size[j].ysize = sizenode->ysize;
  515.         fonts[i].size[j].styles = sizenode->styles;
  516.         for (k = 0; k < fonts[i].size[j].styles; k++)
  517.         fonts[i].size[j].style[k] = sizenode->style[k];
  518.         fonts[i].size[j].stylesel = 0;
  519.         fonts[i].size[j].flags = sizenode->flags;
  520.         sizenode = sizenode->next;
  521.     }
  522.     fonts[i].sizesel = 0;
  523.     search = search->next;
  524.     }
  525.  
  526.     cleartempfonts();
  527.  
  528. }
  529.  
  530. int definescreen()
  531. {
  532.  
  533.     struct RastPort *rp;
  534.  
  535.     int newscreenheight, newscreenwidth, newscreendepth,
  536.     y,
  537.     refresh = TRUE;
  538.  
  539.     ULONG   class;
  540.     struct Gadget *whichgad;
  541.  
  542.     newscreenheight = screenheight;
  543.     newscreenwidth = screenwidth;
  544.     newscreendepth = screendepth;
  545.  
  546.     Request(&ScreenRequesterStructure5, window);
  547.     rp = ScreenRequesterStructure5.ReqLayer->rp;
  548.  
  549.     while (0 == 0) {
  550.  
  551.     if (refresh) {
  552.  
  553.         SetAPen(rp, 0); /* clear those stupid gadgets! */
  554.         for (y = 8; y <= 71; y += 21) {
  555.         RectFill(rp, 16, y, 93, y + 10);
  556.         }
  557.         for (y = 8; y <= 72; y += 16) {
  558.         RectFill(rp, 206, y, 283, y + 10);
  559.         }
  560.  
  561.         /* non-elegant, but it works */
  562.  
  563.         ScreenGadget9.Flags = NULL;
  564.         ScreenGadget10.Flags = NULL;
  565.         ScreenGadget11.Flags = NULL;
  566.         ScreenGadget12.Flags = NULL;
  567.         ScreenGadget13.Flags = NULL;
  568.         ScreenGadget14.Flags = NULL;
  569.         ScreenGadget15.Flags = NULL;
  570.         ScreenGadget16.Flags = NULL;
  571.         ScreenGadget17.Flags = NULL;
  572.  
  573.         if ((newscreenwidth == 320) && (newscreenheight == 200)) {
  574.         ScreenGadget9.Flags = SELECTED;
  575.         }
  576.         if ((newscreenwidth == 320) && (newscreenheight == 400)) {
  577.         ScreenGadget10.Flags = SELECTED;
  578.         }
  579.         if ((newscreenwidth == 640) && (newscreenheight == 200)) {
  580.         ScreenGadget11.Flags = SELECTED;
  581.         }
  582.         if ((newscreenwidth == 640) && (newscreenheight == 400)) {
  583.         ScreenGadget12.Flags = SELECTED;
  584.         }
  585.  
  586.         switch (newscreendepth) {
  587.         case 1: ScreenGadget13.Flags = SELECTED;
  588.             break;
  589.         case 2: ScreenGadget14.Flags = SELECTED;
  590.             break;
  591.         case 3: ScreenGadget15.Flags = SELECTED;
  592.             break;
  593.         case 4: ScreenGadget16.Flags = SELECTED;
  594.             break;
  595.         case 5: ScreenGadget17.Flags = SELECTED;
  596.             break;
  597.         }
  598.  
  599.         if (newscreenwidth == 640) {
  600.         OffGadget(&ScreenGadget17, window, &ScreenRequesterStructure5);
  601.         }
  602.         else {
  603.         OnGadget(&ScreenGadget17, window, &ScreenRequesterStructure5);
  604.         }
  605.  
  606.         refresh = FALSE;
  607.  
  608.     }
  609.  
  610.     message = (struct IntuiMessage *)GetMsg(window->UserPort);
  611.     if (message != 0) {
  612.         class = message->Class;
  613.         whichgad = (struct Gadget *)message->IAddress;
  614.         ReplyMsg(message);
  615.  
  616.         if (class == GADGETUP) {
  617.         refresh = TRUE;
  618.         if (whichgad->GadgetID <= 5) {
  619.             newscreendepth = whichgad->GadgetID;
  620.         }
  621.         switch (whichgad->GadgetID) {
  622.             case 11: newscreenwidth = 320;
  623.                  newscreenheight = 200;
  624.                  break;
  625.             case 12: newscreenwidth = 320;
  626.                  newscreenheight = 400;
  627.                  break;
  628.             case 13: newscreenwidth = 640;
  629.                  newscreenheight = 200;
  630.                  if (newscreendepth == 5) {
  631.                 newscreendepth = 4;
  632.                  }
  633.                  break;
  634.             case 14: newscreenwidth = 640;
  635.                  newscreenheight = 400;
  636.                  if (newscreendepth == 5) {
  637.                 newscreendepth = 4;
  638.                  }
  639.                  break;
  640.             case 101: screenheight = newscreenheight;
  641.                   screenwidth = newscreenwidth;
  642.                   screendepth = newscreendepth;
  643.                   return(TRUE);
  644.                   break;
  645.             case 102: return(FALSE);
  646.                   break;
  647.         }
  648.         }
  649.     }
  650.     }
  651.  
  652. }
  653.  
  654. void setupscreen()
  655. {
  656.  
  657.     if (window) {
  658.     ClearMenuStrip(window);
  659.     CloseWindow(window);
  660.     }
  661.     if (screen)
  662.     CloseScreen(screen);
  663.  
  664.     NewScreenStructure.Width = screenwidth;
  665.     NewScreenStructure.Height = screenheight;
  666.     NewScreenStructure.Depth = screendepth;
  667.  
  668.     if (screenwidth == 320)
  669.     if (screenheight == 200)
  670.         NewScreenStructure.ViewModes = NULL;
  671.     else
  672.         NewScreenStructure.ViewModes = LACE;
  673.     else
  674.     if (screenheight == 200)
  675.         NewScreenStructure.ViewModes = HIRES;
  676.     else
  677.         NewScreenStructure.ViewModes = HIRES | LACE;
  678.  
  679.     NewWindowStructure1.Width = screenwidth;
  680.     NewWindowStructure1.Height = screenheight;
  681.  
  682.     if (screenwidth == 320) {
  683.     FontRequesterStructure2.LeftEdge = 0;
  684.     AboutRequesterStructure3.LeftEdge = 56;
  685.     FehRequesterStructure4.LeftEdge = 60;
  686.     ScreenRequesterStructure5.LeftEdge = 10;
  687.     DirRequesterStructure6.LeftEdge = 60;
  688.     }
  689.     else {
  690.     FontRequesterStructure2.LeftEdge = 160;
  691.     AboutRequesterStructure3.LeftEdge = 216;
  692.     FehRequesterStructure4.LeftEdge = 220;
  693.     ScreenRequesterStructure5.LeftEdge = 170;
  694.     DirRequesterStructure6.LeftEdge = 220;
  695.     }
  696.  
  697.     if (screenheight == 200) {
  698.     FontRequesterStructure2.TopEdge = 50;
  699.     AboutRequesterStructure3.TopEdge = 50;
  700.     FehRequesterStructure4.TopEdge = 75;
  701.     ScreenRequesterStructure5.TopEdge = 55;
  702.     DirRequesterStructure6.TopEdge = 75;
  703.     }
  704.     else {
  705.     FontRequesterStructure2.TopEdge = 150;
  706.     AboutRequesterStructure3.TopEdge = 150;
  707.     FehRequesterStructure4.TopEdge = 175;
  708.     ScreenRequesterStructure5.TopEdge = 155;
  709.     DirRequesterStructure6.TopEdge = 175;
  710.     }
  711.  
  712.     if ((screen = (struct Screen *)OpenScreen(&NewScreenStructure)) == NULL)
  713.     cleanup("ShowFont: couldn't open the screen.");
  714.     NewWindowStructure1.Screen = screen;
  715.  
  716.     if ((window = (struct Window *)OpenWindow(&NewWindowStructure1)) == NULL)
  717.     cleanup("ShowFont: couldn't open the window.");
  718.     rp = window->RPort;
  719.  
  720.     SetMenuStrip(window, &Menu1);
  721.  
  722. }
  723.  
  724. int findfont()
  725. {
  726.  
  727.     char searchname[FONTNAMELEN + 6];
  728.  
  729.     int low, mid, high;
  730.  
  731.     low = 0;
  732.     high = numfonts - 1;
  733.     while (low <= high) {
  734.     mid = (low + high) / 2;
  735.     strcpy(searchname, fonts[mid].name);
  736.     strcat(searchname, ".font");
  737.     if (stricmp(fontname, searchname) < 0)
  738.         high = mid - 1;
  739.     else
  740.         if (stricmp(fontname, searchname) > 0)
  741.         low = mid + 1;
  742.         else
  743.         return(mid);
  744.     }
  745.  
  746.     return(0);
  747.  
  748. }
  749.  
  750. USHORT proppos(int line, int maxline)
  751. {
  752.  
  753.     if (maxline == 1)
  754.     return((USHORT)MAXBODY);
  755.     else
  756.     return((USHORT)((MAXBODY * (line - 1)) / (maxline - 1)));
  757.  
  758. }
  759.  
  760. USHORT propsize(int display, int maxdisplay)
  761. {
  762.  
  763.     if (display >= maxdisplay)
  764.     return((USHORT)MAXPOT);
  765.     else
  766.     return((USHORT)((MAXPOT * display) / maxdisplay));
  767.  
  768. }
  769.  
  770. int propline(USHORT proppos, int maxline)
  771. {
  772.  
  773.     return((proppos * maxline) / MAXPOT);
  774.  
  775. }
  776.  
  777. void refresh1(struct RastPort *rp)
  778. {
  779.  
  780.     register loop,
  781.          x = NAMEXPOS,
  782.          y = TOPYPOS + BASELINE;
  783.  
  784.     char namestring[NAMELEN + 1];
  785.  
  786.     SetAPen(rp, 1);
  787.     SetBPen(rp, 0);
  788.  
  789.     for (loop = 0; loop < MAXDISPLAY; loop++) {
  790.     Move(rp, x, y);
  791.     SetDrMd(rp, JAM2);
  792.     if ((nameline + loop) < numfonts) {
  793.         if ((nameline + loop) == namesel)
  794.         SetDrMd(rp, JAM2 | INVERSVID);
  795.         sprintf(namestring, "%-20s", fonts[nameline + loop].name);
  796.         Text(rp, namestring, NAMELEN);
  797.     }
  798.     else
  799.         Text(rp, "                    ", NAMELEN);
  800.     y += YINCR;
  801.     }
  802.  
  803. }
  804.  
  805. void refresh2(struct RastPort *rp)
  806. {
  807.  
  808.     register loop,
  809.          x = SIZEXPOS,
  810.          y = TOPYPOS + BASELINE;
  811.  
  812.     char sizestring[3 + 1];
  813.  
  814.     for (loop = 0; loop < MAXDISPLAY; loop++) {
  815.     Move(rp, x, y);
  816.     SetDrMd(rp, JAM2);
  817.     SetBPen(rp, 0);
  818.     if ((sizeline + loop) < SIZES) {
  819.         SetAPen(rp, 1);
  820.         if (fonts[namesel].size[sizeline + loop].flags & FPF_PROPORTIONAL)
  821.         SetAPen(rp, 3);
  822.         if ((sizeline + loop) == SIZESEL)
  823.         SetDrMd(rp, JAM2 | INVERSVID);
  824.         sprintf(sizestring, "%3d", fonts[namesel].size[sizeline + loop].ysize);
  825.         Text(rp, sizestring, 3);
  826.     }
  827.     else
  828.         Text(rp, "   ", 3);
  829.     y += YINCR;
  830.     }
  831.  
  832. }
  833.  
  834. void refresh3(struct RastPort *rp)
  835. {
  836.  
  837.     register x = STYLXPOS,
  838.          y = TOPYPOS + BASELINE,
  839.          loop, i;
  840.  
  841.     unsigned char styles[NUMSTYLES];
  842.  
  843.     SetAPen(rp, 1);
  844.     SetBPen(rp, 0);
  845.  
  846.     for (loop = 0; loop < MAXDISPLAY; loop++) {
  847.     Move(rp, x, y);
  848.     SetDrMd(rp, JAM2);
  849.     if ((loop + styleline) == STYLESEL)
  850.         SetDrMd(rp, JAM2 | INVERSVID);
  851.     if ((loop + styleline) < STYLES) {
  852.         for (i = 0; i < NUMSTYLES; i++) {
  853.         styles[i] = '-';
  854.         }
  855.         if ((STYLE[(loop + styleline)] | 1) == STYLE[(loop + styleline)]) {
  856.         styles[0] = 'U';
  857.         }
  858.         if ((STYLE[(loop + styleline)] | 2) == STYLE[(loop + styleline)]) {
  859.         styles[1] = 'B';
  860.         }
  861.         if ((STYLE[(loop + styleline)] | 4) == STYLE[(loop + styleline)]) {
  862.         styles[2] = 'I';
  863.         }
  864.         if ((STYLE[(loop + styleline)] | 8) == STYLE[(loop + styleline)]) {
  865.         styles[3] = 'E';
  866.         }
  867.         Text(rp, styles, NUMSTYLES);
  868.     }
  869.     else {
  870.         for (i = 0; i < NUMSTYLES; i++) {
  871.         styles[i] = ' ';
  872.         }
  873.         Text(rp, styles, NUMSTYLES);
  874.     }
  875.     y += YINCR;
  876.     }
  877.  
  878. }
  879.  
  880. void updateprop(struct Gadget *prop, struct Requester *requester, USHORT proppos, USHORT propsize)
  881. {
  882.  
  883.     NewModifyProp(prop, window, requester, AUTOKNOB | FREEVERT, -1, proppos, -1, propsize, 1);
  884.  
  885. }
  886.  
  887. /* updatetype =  1 : refresh 1        */
  888. /*             update 2, 3    */
  889. /*             refresh 2, 3   */
  890. /*         2 : refresh 2        */
  891. /*             update 3        */
  892. /*             refresh 3        */
  893. /*         3 : refresh 3        */
  894. /*        10 : arrow 1, u/r 1 */
  895. /*        20 : arrow 2, u/r 2 */
  896. /*        30 : arrow 3, u/r 3 */
  897. void duhprop(struct RastPort *rp, int updatetype)
  898. {
  899.  
  900.     if (updatetype == 1) {
  901.     rsizelastline = (SIZES - MAXDISPLAY) + 1;
  902.     if (rsizelastline < 1)
  903.         rsizelastline = 1;
  904.     sizeline = SIZESEL;
  905.     if ((sizeline + 1) >= rsizelastline)
  906.         sizeline = rsizelastline - 1;
  907.     sizepropsize = propsize(MAXDISPLAY, SIZES);
  908.     sizeproppos = proppos((sizeline + 1), rsizelastline);
  909.     }
  910.     if (updatetype < 3) {
  911.     rstylelastline = (STYLES - MAXDISPLAY) + 1;
  912.     if (rstylelastline < 1)
  913.         rstylelastline = 1;
  914.     styleline = STYLESEL;
  915.     if ((styleline + 1) >= rstylelastline)
  916.         styleline = rstylelastline - 1;
  917.     stylepropsize = propsize(MAXDISPLAY, STYLES);
  918.     styleproppos = proppos((styleline + 1), rstylelastline);
  919.     }
  920.  
  921.     switch (updatetype) {
  922.      case 10: fontproppos = proppos((nameline + 1), rfontlastline);
  923.           break;
  924.      case 20: sizeproppos = proppos((sizeline + 1), rsizelastline);
  925.           break;
  926.      case 30: styleproppos = proppos((styleline + 1), rstylelastline);
  927.           break;
  928.     }
  929.  
  930.     switch (updatetype) {
  931.     case  1: refresh1(rp);
  932.          updateprop(&FontSize, &FontRequesterStructure2, sizeproppos, sizepropsize);
  933.          updateprop(&FontStyle, &FontRequesterStructure2, styleproppos, stylepropsize);
  934.          refresh2(rp);
  935.          refresh3(rp);
  936.          break;
  937.     case  2: refresh2(rp);
  938.          updateprop(&FontStyle, &FontRequesterStructure2, styleproppos, stylepropsize);
  939.          refresh3(rp);
  940.          break;
  941.     case  3: refresh3(rp);
  942.          break;
  943.     case 10: updateprop(&FontFont, &FontRequesterStructure2, fontproppos, fontpropsize);
  944.          refresh1(rp);
  945.          break;
  946.     case 20: updateprop(&FontSize, &FontRequesterStructure2, sizeproppos, sizepropsize);
  947.          refresh2(rp);
  948.          break;
  949.     case 30: updateprop(&FontStyle, &FontRequesterStructure2, styleproppos, stylepropsize);
  950.          refresh3(rp);
  951.          break;
  952.     }
  953.  
  954. }
  955.  
  956. int selectfont()
  957. {
  958.  
  959.     struct RastPort *rp;
  960.  
  961.     int returnvalue,
  962.     refreshhow,
  963.     x, y;
  964.  
  965.     ULONG  class;
  966.  
  967.     Request(&FontRequesterStructure2, window);
  968.     rp = FontRequesterStructure2.ReqLayer->rp;
  969.  
  970.     namesel = findfont();
  971.  
  972.     rfontlastline = numfonts - MAXDISPLAY + 1;
  973.     if (rfontlastline < 1)
  974.     rfontlastline = 1;
  975.     fontpropsize = propsize(MAXDISPLAY, numfonts);
  976.  
  977.     nameline = namesel;
  978.     if ((nameline + 1) >= rfontlastline)
  979.     nameline = rfontlastline - 1;
  980.  
  981.     duhprop(rp, 1);
  982.     duhprop(rp, 10);
  983.  
  984.     refreshhow = 0;
  985.     returnvalue = 0;
  986.  
  987.     while (returnvalue == 0) {
  988.     switch (refreshhow) {
  989.         case 11: if (nameline > 0)
  990.              --nameline;
  991.              duhprop(rp, 10);
  992.              break;
  993.         case 12: nameline = propline(FontFontFontSInfo.VertPot, rfontlastline);
  994.              if ((nameline + 1) >= rfontlastline)
  995.              nameline = rfontlastline - 1;
  996.              refresh1(rp);
  997.              break;
  998.         case 13: if ((nameline + 1) < rfontlastline)
  999.              ++nameline;
  1000.              duhprop(rp, 10);
  1001.              break;
  1002.         case 21: if (sizeline > 0)
  1003.              --sizeline;
  1004.              duhprop(rp, 20);
  1005.              break;
  1006.         case 22: sizeline = propline(FontFontSizeSInfo.VertPot, rsizelastline);
  1007.              if ((sizeline + 1) >= rsizelastline)
  1008.              sizeline = rsizelastline - 1;
  1009.              refresh2(rp);
  1010.              break;
  1011.         case 23: if ((sizeline + 1) < rsizelastline)
  1012.              ++sizeline;
  1013.              duhprop(rp, 20);
  1014.              break;
  1015.         case 31: if (styleline > 0)
  1016.              --styleline;
  1017.              duhprop(rp, 30);
  1018.              break;
  1019.         case 32: styleline = propline(FontFontStyleSInfo.VertPot, rstylelastline);
  1020.              if ((styleline + 1) >= rstylelastline)
  1021.              styleline = rstylelastline - 1;
  1022.              refresh3(rp);
  1023.              break;
  1024.         case 33: if ((styleline + 1) < rstylelastline)
  1025.              ++styleline;
  1026.              duhprop(rp, 30);
  1027.              break;
  1028.     }
  1029.  
  1030.     message = (struct IntuiMessage *)GetMsg(window->UserPort);
  1031.     if (message != 0) {
  1032.         class = message->Class;
  1033.         x = message->MouseX - FontRequesterStructure2.LeftEdge;
  1034.         y = message->MouseY - FontRequesterStructure2.TopEdge;
  1035.         whichgad = (struct Gadget *)message->IAddress;
  1036.         ReplyMsg(message);
  1037.  
  1038.         if (class == GADGETDOWN) {
  1039.         refreshhow = whichgad->GadgetID;
  1040.         }
  1041.         if (class == GADGETUP) {
  1042.         switch (whichgad->GadgetID) {
  1043.             case 101: returnvalue = 1;
  1044.                   break;
  1045.             case 102: returnvalue = -1;
  1046.                   break;
  1047.         }
  1048.         refreshhow = 0; /* no more auto-scrolling */
  1049.         }
  1050.         if (class == MOUSEBUTTONS) {
  1051.         if ((y >= 0) && (y < 100) && (x >= 0) && (x < 320)) {
  1052.             y -= TOPYPOS;
  1053.             y = y / YINCR;
  1054.             if (y < MAXDISPLAY) {
  1055.             if ((x >= NAMEXPOS) && (x < (NAMEXPOS + NAMELEN * XINCR))) {
  1056.                 if (namesel == (nameline + y)) {
  1057.                 returnvalue = 1;
  1058.                 EndRequest(&FontRequesterStructure2, window);
  1059.                 }
  1060.                 else {
  1061.                 namesel = nameline + y;
  1062.                 if (namesel >= numfonts)
  1063.                     namesel = numfonts - 1;
  1064.                 duhprop(rp, 1);
  1065.                 }
  1066.             }
  1067.             if ((x >= SIZEXPOS) && (x < (SIZEXPOS + 3 * XINCR))) {
  1068.                 if (SIZESEL == (sizeline + y)) {
  1069.                 returnvalue = 1;
  1070.                 EndRequest(&FontRequesterStructure2, window);
  1071.                 }
  1072.                 else {
  1073.                 SIZESEL = sizeline + y;
  1074.                 if (SIZESEL >= SIZES)
  1075.                     SIZESEL = SIZES - 1;
  1076.                 duhprop(rp, 2);
  1077.                 }
  1078.             }
  1079.             if ((x >= STYLXPOS) && (x < (STYLXPOS + 4 * XINCR))) {
  1080.                 if (STYLESEL == (styleline + y)) {
  1081.                 returnvalue = 1;
  1082.                 EndRequest(&FontRequesterStructure2, window);
  1083.                 }
  1084.                 else {
  1085.                 STYLESEL = styleline + y;
  1086.                 if (STYLESEL >= STYLES)
  1087.                     STYLESEL = STYLES - 1;
  1088.                 duhprop(rp, 3);
  1089.                 }
  1090.             }
  1091.             }
  1092.         }
  1093.         }
  1094.     }
  1095.     }
  1096.  
  1097.     if (returnvalue == 1) {
  1098.     strcpy(fontname, fonts[namesel].name);
  1099.     strcat(fontname, ".font");
  1100.     myfont.ta_YSize = fonts[namesel].size[SIZESEL].ysize;
  1101.     myfont.ta_Style = STYLE[STYLESEL];
  1102.     myfont.ta_Flags = fonts[namesel].size[SIZESEL].flags;
  1103.     }
  1104.  
  1105.     return(returnvalue);
  1106.  
  1107. }
  1108.  
  1109. void *findfonts()
  1110. {
  1111.  
  1112.     struct RootNode *root;
  1113.     struct DosInfo *info;
  1114.     struct DevInfo *dev_node;
  1115.  
  1116.     char *name;
  1117.  
  1118.     root=(struct RootNode *)DOSBase->dl_Root;
  1119.     info=(struct DosInfo *)BADDR(root->rn_Info);
  1120.  
  1121.     Forbid();
  1122.  
  1123.     for (dev_node = (struct DevInfo *)BADDR(info->di_DevInfo);
  1124.      dev_node->dvi_Next != NULL;
  1125.      dev_node = (struct DevInfo *)BADDR(dev_node->dvi_Next)) {
  1126.  
  1127.     name = (char *)BADDR(dev_node->dvi_Name);
  1128.     if ((*name == 5) && (strnicmp((name + 1), "FONTS", 5) == 0)) {
  1129.         return(dev_node);
  1130.     }
  1131.  
  1132.     }
  1133.  
  1134.     return(NULL);
  1135.  
  1136. }
  1137.  
  1138. int changefontsdir()
  1139. {
  1140.  
  1141.     struct DevInfo *info;
  1142.     struct FileLock *lock;
  1143.  
  1144.     ULONG class;
  1145.     struct Gadget *whichgad;
  1146.  
  1147.     int quit;
  1148.  
  1149.     Request(&DirRequesterStructure6, window);
  1150.     Delay(10);
  1151.     ActivateGadget(&DirNewDir, window, &DirRequesterStructure6);
  1152.  
  1153.     quit = FALSE;
  1154.  
  1155.     while (!quit) {
  1156.     while ((message = (struct IntuiMessage *)GetMsg(window->UserPort)) == 0) { }
  1157.     class = message->Class;
  1158.     whichgad = (struct Gadget *)message->IAddress;
  1159.     ReplyMsg(message);
  1160.  
  1161.     if (class == GADGETUP) {
  1162.         quit = whichgad->GadgetID;
  1163.     }
  1164.     }
  1165.  
  1166.     if (quit == 101) {
  1167.     lock = (struct FileLock *)Lock(DirDirNewDirSIBuff, ACCESS_READ);
  1168.     if (lock == NULL) {
  1169.         error("DIR NOT FOUND!");
  1170.         return(FALSE);
  1171.     }
  1172.     else {
  1173.         info = (struct DevInfo *)findfonts();
  1174.         UnLock(info->dvi_Lock);
  1175.         info->dvi_Lock = (BPTR)lock;
  1176.         info->dvi_Task = (APTR)(DeviceProc(DirDirNewDirSIBuff));
  1177.         Permit();
  1178.         return(TRUE);
  1179.     }
  1180.     }
  1181.     else {
  1182.     return(FALSE);
  1183.     }
  1184.  
  1185. }
  1186.  
  1187. void makewindowtitle(char *s)
  1188. {
  1189.  
  1190.     stccpy(s, fontname, (strlen(fontname) - 4));
  1191.     sprintf(s + strlen(s), " - %d", myfont.ta_YSize);
  1192.     if ((myfont.ta_Style | 1) == myfont.ta_Style) {
  1193.     strcat(s, "u");
  1194.     }
  1195.     if ((myfont.ta_Style | 2) == myfont.ta_Style) {
  1196.     strcat(s, "b");
  1197.     }
  1198.     if ((myfont.ta_Style | 4) == myfont.ta_Style) {
  1199.     strcat(s, "i");
  1200.     }
  1201.     if ((myfont.ta_Style | 8) == myfont.ta_Style) {
  1202.     strcat(s, "e");
  1203.     }
  1204.  
  1205. }
  1206.  
  1207. void main(int argc, char *argv[])
  1208. {
  1209.  
  1210.     int cont = TRUE,
  1211.     rethinkfont = TRUE;
  1212.  
  1213.     ULONG   class;
  1214.     USHORT  code;
  1215.  
  1216.     int line, maxline,
  1217.     yarea,
  1218.     startchar,
  1219.     len, pixels,
  1220.     whichmenu, whichitem,
  1221.     wproplastline,
  1222.     refreshhow,
  1223.     x, y;
  1224.  
  1225.     char windowtitle[81];
  1226.  
  1227.     USHORT numy, pos, size;
  1228.  
  1229.     register loop, i;
  1230.  
  1231.     UBYTE textline[256], character;
  1232.  
  1233.     if ((argc == 2) && (*argv[1] == '?'))
  1234.     cleanup("Usage: ShowFont [font_name] [font_size] [ubie]");
  1235.  
  1236.     if ((IntuitionBase = (struct IntuitionBase *)
  1237.         OpenLibrary("intuition.library", 0)) == NULL)
  1238.     cleanup("ShowFont: couldn't open 'intuition.library'.");
  1239.  
  1240.     if ((GfxBase = (struct GfxBase *)
  1241.         OpenLibrary("graphics.library", 0)) == NULL)
  1242.     cleanup("ShowFont: couldn't open 'graphics.library'.");
  1243.  
  1244.     if ((DiskfontBase = (struct DiskfontBase *)
  1245.         OpenLibrary("diskfont.library", 0)) == NULL)
  1246.     cleanup("ShowFont: couldn't open 'diskfont.library'.");
  1247.  
  1248.     setupscreen();
  1249.  
  1250.     fonts = NULL;
  1251.  
  1252.     if (argc == 1)
  1253.     strcpy(fontname, "Topaz.font");
  1254.     else
  1255.     sprintf(fontname, "%s.font", argv[1]);
  1256.     if (argc < 3) {
  1257.     readfonts();
  1258.     selectfont();
  1259.     }
  1260.     else {
  1261.     myfont.ta_YSize = atoi(argv[2]);
  1262.     if (argc == 4) {
  1263.         myfont.ta_Style = FS_NORMAL;
  1264.         for (loop = 0; loop < strlen(argv[3]); loop++) {
  1265.         switch (*(argv[3] + loop) & ~0x20) {
  1266.             case 'U': myfont.ta_Style |= 1;
  1267.                   break;
  1268.             case 'B': myfont.ta_Style |= 2;
  1269.                   break;
  1270.             case 'I': myfont.ta_Style |= 4;
  1271.                   break;
  1272.             case 'E': myfont.ta_Style |= 8;
  1273.                   break;
  1274.         }
  1275.         }
  1276.     }
  1277.     }
  1278.  
  1279.     for (i = 0; i < 256; ++i)
  1280.     fontline[i].length = 0;
  1281.  
  1282.     while (cont) {
  1283.  
  1284.     if (rethinkfont) {
  1285.  
  1286.         if (font)
  1287.         CloseFont(font);
  1288.  
  1289.         if ((font = (struct TextFont *)OpenDiskFont(&myfont)) == NULL) {
  1290.         error("FONT NOT FOUND!");
  1291.         strcpy(fontname, "Topaz.font");
  1292.         myfont.ta_YSize = 8;
  1293.         myfont.ta_Style = FS_NORMAL;
  1294.         myfont.ta_Flags = FPF_ROMFONT;
  1295.         if ((font = (struct TextFont *)OpenDiskFont(&myfont)) == NULL) {
  1296.             cleanup("ShowFont: couldn't default to Topaz-8!");
  1297.         }
  1298.         }
  1299.  
  1300.         if (myfont.ta_YSize > screenheight) {
  1301.         screenheight = 400;
  1302.         setupscreen();
  1303.         }
  1304.  
  1305.         SetFont(rp, font);
  1306.  
  1307.         clearfontlines();
  1308.  
  1309.         startchar = font->tf_LoChar;
  1310.         line = 0;
  1311.         len = 0;
  1312.  
  1313.         for (loop = font->tf_LoChar; loop <= font->tf_HiChar; ++loop) {
  1314.         textline[len++] = loop;
  1315.         pixels = TextLength(rp, textline, len) + window->BorderLeft;
  1316.         if (pixels > (screenwidth - XAREA)) {
  1317.             --len;
  1318.             fontline[line].string = (UBYTE *)AllocMem(len, MEMF_CLEAR);
  1319.             if (fontline[line].string == NULL)
  1320.             cleanup("ShowFont: couldn't allocate 'fontline' memory!");
  1321.             for (i = startchar; i < loop; ++i)
  1322.             fontline[line].string[i - startchar] = i;
  1323.             fontline[line].length = len;
  1324.             startchar = loop;
  1325.             ++line;
  1326.             len = 0;
  1327.             --loop; /* must go back and insert that character */
  1328.         }
  1329.         else
  1330.             if (loop == font->tf_HiChar) {
  1331.             fontline[line].string = (UBYTE *)AllocMem(len, MEMF_CLEAR);
  1332.             if (fontline[line].string == NULL)
  1333.                 cleanup("ShowFont: couldn't allocate 'fontline' memory!");
  1334.             for (i = startchar; i <= font->tf_HiChar; ++i)
  1335.                 fontline[line].string[i - startchar] = i;
  1336.             fontline[line].length = len;
  1337.             ++line;
  1338.             }
  1339.         }
  1340.  
  1341.         maxline = line;
  1342.         line = 0;
  1343.         yarea = screenheight - (window->BorderTop + window->BorderBottom);
  1344.         numy = yarea / font->tf_YSize;
  1345.  
  1346.         wproplastline = (maxline - numy) + 1;
  1347.         if (wproplastline < 1)
  1348.         wproplastline = 1;
  1349.  
  1350.         size = propsize(numy, maxline);
  1351.  
  1352.         makewindowtitle(windowtitle);
  1353.  
  1354.         makewindowtitle(windowtitle);
  1355.         SetWindowTitles(window, windowtitle, -1);
  1356.  
  1357.         rethinkfont = FALSE;
  1358.         refreshhow = 99;    /* refresh it once only */
  1359.     }
  1360.  
  1361.     switch (refreshhow) {
  1362.         case  1: if (line > 0)
  1363.              --line;
  1364.              break;
  1365.         case  2: pos = PropSInfo.VertPot;
  1366.              line = propline(pos, wproplastline);
  1367.              if ((line + 1) > wproplastline)
  1368.              line = wproplastline - 1;
  1369.              break;
  1370.         case  3: if ((line + 1) < wproplastline)
  1371.              ++line;
  1372.              break;
  1373.     }
  1374.  
  1375.     if (refreshhow != 0) {
  1376.  
  1377.         pos = proppos((line + 1), wproplastline);
  1378.  
  1379.         if (refreshhow != 2)    /* don't blink the slider */
  1380.         NewModifyProp(&Prop, window, NULL, AUTOKNOB | FREEVERT, -1, pos, -1, size, 1);
  1381.  
  1382.         WaitTOF();  /* might just possibly reduce blinking */
  1383.         SetAPen(rp, 0); /* clear the screen */
  1384.         RectFill(rp, window->BorderLeft, window->BorderTop, (screenwidth - XAREA), (screenheight - window->BorderBottom));
  1385.  
  1386.         SetAPen(rp, 1);
  1387.         SetBPen(rp, 0);
  1388.         SetDrMd(rp, JAM2);
  1389.  
  1390.         for (i = line; i < (line + numy); ++i) {
  1391.         Move(rp, window->BorderLeft, ((i - line) * font->tf_YSize) + window->BorderTop + font->tf_Baseline);
  1392.         Text(rp, fontline[i].string, fontline[i].length);
  1393.         }
  1394.  
  1395.         if (refreshhow == 99)
  1396.         refreshhow = 0; /* for initial refreshment only */
  1397.     }
  1398.  
  1399.     message = (struct IntuiMessage *)GetMsg(window->UserPort);
  1400.     if (message != 0) {
  1401.         class = message->Class;
  1402.         code  = message->Code;
  1403.         whichgad = (struct Gadget *)message->IAddress;
  1404.         x = message->MouseX;
  1405.         y = message->MouseY;
  1406.         ReplyMsg(message);
  1407.  
  1408.         if (class == CLOSEWINDOW)
  1409.         cont = FALSE;
  1410.         if (class == GADGETDOWN)
  1411.         refreshhow = whichgad->GadgetID;
  1412.         if (class == GADGETUP)
  1413.         refreshhow = 0; /* stop scrolling */
  1414.         if (class == MOUSEBUTTONS) {
  1415.         y -= window->BorderTop;
  1416.         y /= font->tf_YSize;
  1417.         if (y < maxline) {
  1418.             for (loop = 0; loop < fontline[(y + line)].length; loop++) {
  1419.             textline[loop] = fontline[(y + line)].string[loop];
  1420.             pixels = TextLength(rp, textline, (loop + 1)) + window->BorderLeft;
  1421.             if (x <= pixels)
  1422.                 break;
  1423.             }
  1424.             character = fontline[(y + line)].string[loop];
  1425.             switch (qualifiers[character]) {
  1426.             case 0: textline[0] = '\0';
  1427.                 break;
  1428.             case 1: strcpy(textline, "CONTROL-");
  1429.                 break;
  1430.             case 2: strcpy(textline, "SHIFT-");
  1431.                 break;
  1432.             case 3: strcpy(textline, "ALT-");
  1433.                 break;
  1434.             case 4: strcpy(textline, "ALT-SHIFT-");
  1435.                 break;
  1436.             case 5: strcpy(textline, "CONTROL-ALT-");
  1437.                 break;
  1438.             }
  1439.             len = strlen(textline);
  1440.             textline[len] = whichkey[character];
  1441.             textline[len + 1] = '\0';
  1442.             makewindowtitle(windowtitle);
  1443.             strcat(windowtitle, " (");
  1444.             strcat(windowtitle, textline);
  1445.             sprintf(windowtitle + strlen(windowtitle),
  1446.             ") [Dec %03d Hex $%02x]", character, character);
  1447.             SetWindowTitles(window, windowtitle, -1);
  1448.             while ((message = (struct IntuiMessage *)GetMsg(window->UserPort)) != 0)
  1449.             ReplyMsg(message);
  1450.         }
  1451.         }
  1452.         if (class == MENUPICK) {
  1453.         if (code != MENUNULL) {
  1454.             whichmenu = MENUNUM(code);
  1455.             whichitem = ITEMNUM(code);
  1456.             switch (whichmenu) {
  1457.             case 0 : switch (whichitem) {
  1458.                     case 0: Request(&AboutRequesterStructure3, window); /* about */
  1459.                         while ((message = (struct IntuiMessage *)GetMsg(window->UserPort)) != 0)
  1460.                         ReplyMsg(message);
  1461.                         break;
  1462.                     case 1: cont = FALSE; /* quit */
  1463.                         break;
  1464.                  }
  1465.                  break;
  1466.             case 1 : switch (whichitem) {
  1467.                     case 0: if (changefontsdir() == TRUE) {
  1468.                         readfonts();
  1469.                         if (selectfont() == 1) {
  1470.                             rethinkfont = TRUE;
  1471.                         }
  1472.                         }
  1473.                         break;
  1474.                     case 1: if (fonts == NULL)
  1475.                         readfonts();
  1476.                         if (selectfont() == 1)
  1477.                         rethinkfont = TRUE;
  1478.                         break; /* font selection */
  1479.                  }
  1480.                  break;
  1481.             case 2 : if (definescreen() == TRUE) {
  1482.                      setupscreen();
  1483.                      rethinkfont = TRUE;
  1484.                  }
  1485.                  break;
  1486.             }
  1487.         }
  1488.         }
  1489.     }
  1490.     }
  1491.  
  1492.     cleanup(NULL);
  1493.  
  1494. }
  1495.